-
Notifications
You must be signed in to change notification settings - Fork 798
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set up testing-library/react for testing jetpack blocks and add example tests to WhatsApp block #18582
Conversation
Caution: This PR has changes that must be merged to WordPress.com |
This is an automated check which relies on |
697470b
to
05eca89
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This tests well for me as per the instructions 👍
It will be great to get some guidelines around what will qualify as sufficient coverage for individual blocks.
While testing the WhatsApp button, I found that with both the latest Gutenberg plugin and Jetpack, the toolbar menu is squashed and too narrow. This was the same with Jetpack master as well as this PR branch. Perhaps it could be addressed in a separate PR?
Without Gutenberg | With Gutenberg |
---|---|
projects/plugins/jetpack/extensions/blocks/send-a-message/whatsapp-button/test/settings.js
Outdated
Show resolved
Hide resolved
@@ -200,57 +60,20 @@ export default function WhatsAppButtonEdit( { attributes, setAttributes, classNa | |||
<div className={ getBlockClassNames() }> | |||
{ ToolbarGroup && ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need this check for ToolbarGroup
? Was this to support an older version of WP?
It looks like most other blocks in Jetpack don't make this check. This would only tidy the code a tiny bit so it's fine, just more for my understanding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeh it seems like the only reason to have this would be for older versions of gutenberg - @apeatling do you know if that is the case and if it is still needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just thought I'd look this one up. I think the check isn't needed any more, the ToolbarGroup
component was added in WordPress/gutenberg#18534 in GB 7.0, and from looking at the Versions in WordPress doc, that was included in WP 5.4.0. According to the readme.txt
the required WP version for Jetpack is currently WP 5.5, so we should be good :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for doing that research @andrewserong - have removed that check now
onClick={ onToggle } | ||
onKeyDown={ openOnArrowDown } | ||
icon={ renderMaterialIcon( | ||
<Path d="M10.82 12.49c.02-.16.04-.32.04-.49 0-.17-.02-.33-.04-.49l1.08-.82c.1-.07.12-.21.06-.32l-1.03-1.73c-.06-.11-.2-.15-.31-.11l-1.28.5c-.27-.2-.56-.36-.87-.49l-.2-1.33c0-.12-.11-.21-.24-.21H5.98c-.13 0-.24.09-.26.21l-.2 1.32c-.31.12-.6.3-.87.49l-1.28-.5c-.12-.05-.25 0-.31.11l-1.03 1.73c-.06.12-.03.25.07.33l1.08.82c-.02.16-.03.33-.03.49 0 .17.02.33.04.49l-1.09.83c-.1.07-.12.21-.06.32l1.03 1.73c.06.11.2.15.31.11l1.28-.5c.27.2.56.36.87.49l.2 1.32c.01.12.12.21.25.21h2.06c.13 0 .24-.09.25-.21l.2-1.32c.31-.12.6-.3.87-.49l1.28.5c.12.05.25 0 .31-.11l1.03-1.73c.06-.11.04-.24-.06-.32l-1.1-.83zM7 13.75c-.99 0-1.8-.78-1.8-1.75s.81-1.75 1.8-1.75 1.8.78 1.8 1.75S8 13.75 7 13.75zM18 1.01L8 1c-1.1 0-2 .9-2 2v3h2V5h10v14H8v-1H6v3c0 1.1.9 2 2 2h10c1.1 0 2-.9 2-2V3c0-1.1-.9-1.99-2-1.99z" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While we are refactoring, would this icon path be a candidate to move to its own file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to keep the refactoring down to just the parts required for better testing so the PR doesn't get too big, and cluttered with changes that don't affect testing ... but would be good to include in the follow up PR that looks at the dropdown sizing issue for sure.
Would it make sense to break this up into different components @apeatling e.g. phone number, default message and toggle? Would that be easier and more intuitive than jamming it into a single tool? |
Given @amamujee's question about refactoring this into separate toolbar buttons I think we should defer this to a separate issue/PR |
That probably does make sense - I have added a separate issue for this in the View backlog so we can keep this PR related to the addition of the new testing framework - 212-gh-Automattic/view-design |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This refactor is looking really nice to me! Love the clean, easy to read tests, and it also feels much cleaner having the configuration broken out to a separate component.
Confirmed that the tests pass when running the following:
yarn test-extensions-single extensions/blocks/send-a-message/whatsapp-button/test/edit.js
yarn test-extensions-single extensions/blocks/send-a-message/whatsapp-button/test/configuration.js
Tested the block in a dotcom simple site to confirm it's still working as expected (I'm not that familiar with the block, but didn't run into any issues). Also tested on a local .org install, and it works correctly, opening up WhatsApp if I have it installed on my phone, otherwise opening the WhatsApp website. 👍
I noticed an unrelated styling issue when the focus is active on the front end of the button when using the twentytwentyone theme, so I've raised it separately in #18688
Kraft asked me to look this over with an eye towards whether it fits in with the work we're doing to improve the testing infrastructure of the monorepo as a whole. I'm happy to say that I see nothing to be concerned about here from that perspective, as this is only adding to the existing extension tests within Jetpack the plugin (versus something like creating a whole new kind of test or test runner). I haven't reviewed the specific changes here in detail, but 👍 for adding better tests! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good to me. Although it would need merge from master/rebase
…alidation (#18643) Co-authored-by: Glen Davies <glen.davies@a8c.com>
5125172
to
1ee629e
Compare
Thanks @brbrr, it is rebased now if you are able to give it a tick please. |
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 If you are an automattician, once your PR is ready for review add the "[Status] Needs Team review" label and ask someone from your team review the code. jetpack plugin:
|
Merging this now. I'll let you handle the matching WordPress.com diff. |
@glendaviesnz Could you commit the matching WordPress.com diff? Thank you! |
Done. |
r221623-wpcom |
DO NOT MERGE until #18643 is merged back into this PR
Adds testing-framework/react to allow better unit testing of the Jetpack blocks.
See p1HpG7-b3G-p2 for background.
The philosophy behind testing-framework/react is to as much as possible test components in the same way a user would, so testing output rather than implementation details.
This PR adds the framework and adds unit tests using this approach to the WhatsApp block.
A change was needed to the block structure to pull out the settings to a separate component so they can be tested independently of the gutenberg slots that are normally needed to view these components in the ui - but this has the nice side effect of simplifying the block structure also ... but this means that the WhatsApp block functionality should be tested as part of the testing of this PR.
Sample tests can be run in the
projects/plugins/jetpack
folder with:yarn jest extensions/blocks/send-a-message/whatsapp-button/test/edit.js
yarn jest extensions/blocks/send-a-message/whatsapp-button/test/configuration.js